package com.hibernate.hrm.controller.login;

import com.hibernate.hrm.entity.dto.login.UserInfoDTO;
import com.hibernate.hrm.entity.User;
import com.hibernate.hrm.service.login.AuthService;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
@RequiredArgsConstructor
public class AuthController {

    private final AuthService authService;

    @GetMapping("/login")
    public String login() {
        return "login";
    }

    @GetMapping("/home")
    public String home(@AuthenticationPrincipal User user, Model model) {
        UserInfoDTO userInfo = authService.getUserInfo(user);
        model.addAttribute("userInfo", userInfo);
        model.addAttribute("roleIdValue", user.getRoleId().getRoleId());
        return "home";
    }
}